<?php
namespace app\admin\controller;


use think\Request;

class Setting extends Base{


  public function promotionRule(){

      $rules = model('setting')->getPromotionRule();
      $this->assign('rules',$rules);
      return view('promotionRule');
  }


   public function savePromotionRule(){

      $data = Request::instance()->post();
      model('setting')->savePromotionRule($data,'promotion');
      $this->redirect('promotionRule');
   }


   public function creditRule(){
       $rule = model('setting')->getCreditRule();
       $register = model('setting')->getRule('register_credit');
       $this->assign('register',$register);
       $this->assign('rule',$rule);
      return view('creditRule');
   }


    public function saveCreditRule(){
        $data = Request::instance()->post();
        model('setting')->savePromotionRule($data,'credit');
        $this->redirect('creditRule');
    }


    public function pay(){
        $rule = model('setting')->getPayRule();
        $this->assign('rule',$rule);
        return view('pay');

    }


    public function savePayRule(){

      $data = Request::instance()->post();
      $cert_path = Request::instance()->file('cert_path');
      $key_path = Request::instance()->file('key_path');
      if($cert_path){
          $data['cert_path'] = upload($cert_path,'txt');
      }
        if($key_path){
            $data['key_path'] = upload($key_path,'txt');
        }
      model('setting')->savePromotionRule($data,'pay');
      $this->redirect('pay');
    }


    public function profit(){

        $rule = model('setting')->getProfitRule();
        $this->assign('rule',$rule);
        return view('profit');
    }


    public function saveProfitRule(){
        $data = Request::instance()->post();
        model('setting')->savePromotionRule($data,'profit');
        $this->redirect('profit');
    }









}